home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / spiderweb / src / postscript / outline.web < prev    next >
Encoding:
Text File  |  1993-04-04  |  5.1 KB  |  163 lines

  1. % Copyright 1989, David Love, SERC Daresbury Laboratory under the same
  2. % conditions as the Spider distribution
  3.  
  4. \def\title{PSWEB demonstration -- outline font}
  5. \def\ps{{\sc PostScript}}
  6.  
  7. @*Introduction.
  8. As a simple example of the use of \ps\ \.{WEB} we'll do a
  9. literate re-write of {\sl Program 16 / Making an Outline Font} from the
  10. Adobe blue {\sl Cookbook}, p~199. Most of the text will be directly lifted
  11. from that example.
  12. Compare this with the original!
  13. The \ps\ convention of writing, for instance, |MakeOutlineFont| instead
  14. of the form |make_outline_font| has been carried over from the original
  15. example just this once, contrary to Knuthian lore and my preference.
  16.  
  17. @*2Purpose.
  18. This program defines a general procedure to take one of the built-in
  19. fonts and convert it to an outline font.
  20. (This program will also work for downloadable fonts available from
  21. Adobe Systems, Inc.).
  22.  
  23. @ We need to write out a suitable bounding box comment for \.{\\psfig}.
  24. @u
  25. @=%%BoundingBox: 18 18 577 824@>
  26.  
  27. @ Local storage for the procedure |MakeOutlineFont|.
  28. @u
  29. /makeoutlinedict 7 dict def
  30.  
  31. @*2Function definition and use.
  32. |MakeOutlineFont| takes one of the built-in filled fonts and makes an outlined
  33. font out of it.
  34. It takes four arguments: the name of the font on which to base the outline
  35. version, the new name for the outline font, a stroke width to use on the
  36. outline  and a unique ID.
  37. @u
  38. /MakeOutlineFont  =>% base\_name new\_name stroke\_width ID
  39.  { makeoutlinedict begin
  40.   @<stash the arguments@>
  41.   @<get dictionary of font on which outline version will be based@>
  42.   @<determine how large new font dictionary should be@>
  43.   @<make sure there is room for the unique ID field@>
  44.   @<create dictionary to hold description for outline font@>
  45.   @<copy entries in base font dictionary to outline dictionary, except
  46.     for the FID@>
  47.   @<miscellaneous inserts into the new dictionary@>
  48.   @<make new font@>
  49.   end
  50. } def
  51.  
  52. @ Four arguments as described above.
  53. @<stash...@>=
  54. /uniqueid exch def
  55. /strokewidth exch def
  56. /newfontname exch def
  57. /basefontname exch def
  58.  
  59. @ @<get dictionary...@>=
  60. /basefontdict basefontname findfont def
  61.  
  62. @ @<determine how large...@>=
  63. /numentries basefontdict maxlength 1 add def
  64.  
  65. @ (Not all fonts have unique ID fields initially.
  66. In particlular, the built-in fonts in \ps\ version 23.0 don't.)
  67.  
  68. @<make sure there is room...@>=
  69. basefontdict /UniqueID known not =>
  70.  {/numentries numentries 1 add def} if
  71.  
  72. @ @<create dictionary...@>=
  73. /outfontdict numentries dict def
  74.  
  75. @ @<copy entries...@>=
  76. basefontdict =>
  77.  { exch dup /FID ne
  78. {exch outfontdict 3 1 roll put}
  79. {pop pop}         % ignore the FID pair
  80. ifelse
  81. } forall
  82.  
  83. @ We need to 1) insert the new name into the dictionary
  84. 2) change the paint type to outline
  85. 3) insert the stroke width into the dictionary
  86. 4) insert the new unique ID
  87.  
  88. @<miscellaneous inserts...@>=
  89. outfontdict /FontName newfontname put
  90. outfontdict /PaintType 2 put
  91. outfontdict /StrokeWidth strokewidth put
  92. outfontdict /UniqueID uniqueid put
  93.  
  94. @ In making the outline dictionary into a \ps\ font we ignore the
  95. modified dictionary returned on the stack by |definefont|.
  96. @<make new font@>=
  97. newfontname outfontdict definefont pop
  98.  
  99. @*Use of the procedure and determining new IDs.
  100. We'll make a new font |Helvetica-Outline1| derived from |Helvetica-Bold|.
  101. The results will appear below.
  102.  
  103. @u
  104. /Helvetica-Bold @!/Helvetica-Outline1 @<define stroke width@>
  105. @<determine unique ID@>
  106. MakeOutlineFont
  107.  
  108. @ The stroke width is always specified in the character coordinate system
  109. (1000 units).
  110. The value specified here will yield a one point wide outline when the font is
  111. scaled to 54 points in size.
  112. Note that this outline width changes with different point sizes.
  113. @^stroke width@>
  114. @<define stroke width@>=
  115. 1000 54 div
  116.  
  117. @ To determine the unique id:
  118. If the `base' font already contains a unique ID, add a unique constant to it,
  119. otherwise pick a unique integer and leave that value on the operand stack.
  120. @<determine unique ID@>=
  121. /Helvetica-Bold findfont dup /UniqueID known =>
  122.  {/UniqueID get 1 add}
  123. {pop 1}
  124. ifelse
  125. @ So here are two sizes with this stroke width.
  126. @u
  127. /Helvetica-Outline1 findfont 36 scalefont setfont =>
  128. 72 504 moveto (outline) show <=
  129. /Helvetica-Outline1 findfont 54 scalefont setfont =>
  130.  (outline) show
  131.  
  132. @ Now we'll do one with a different stroke width.
  133. The width of 1000/36 used now yields a one point wide outline when the font
  134. is scaled to 36 point in size.
  135. It yields a 1.5 point outline when the font is scaled to 54 points
  136. in size ($54/36=1.5$).@^stroke width@>
  137. @u
  138. /Helvetica-Bold @!/Helvetica-Outline2 1000 36 div
  139. @<determine unique ID@>
  140. MakeOutlineFont
  141.  
  142. @ And use the different stroke width:
  143. @u
  144. /Helvetica-Outline2 findfont 36 scalefont setfont =>
  145. 72 444 moveto (outline) show <=
  146. /Helvetica-Outline2 findfont 54 scalefont setfont =>
  147.  (outline) show
  148.  
  149. @ Finish off the example:
  150. @u
  151. showpage
  152.  
  153. @*1Results of the examples.
  154. The results of including the \.{TANGLE}d version of this \.{WEB} source
  155. into the \.{WEAVE} output using the \.{\\psfig} macro and a suitable
  156. \.{DVI} to \ps\ converter are given here.  The example has been shrunken
  157. to get it on the page and may be faint on a write-white engine with the
  158. stroke widths defined above.@^stroke width@>@^write-white@>
  159. \input psfig.sty
  160. \centerline{\psfig{figure=outline.ps1,height=6in}}
  161.  
  162. @*Index.
  163.